package org.strangewt.demo.composit;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.strangewt.demo.testdata.Person;
import org.strangewt.demo.testdata.Project;
import org.strangewt.widgets.CompositeBase;
import org.strangewt.widgets.CompositeInput;

public class CompositePerson extends CompositeInput<Person> {

	private Text txFirstName;
	private Text txLastName;
	private Text txAge;
	
	public CompositePerson(Composite parent, int style) {
		super(parent, style);
		
		createControl(this);
	}

	private void createControl(Composite parent) {
		
		setLayout(new GridLayout(2, false));
	
		createLabel(parent, getClass().getName(), 2, 1);
		
		createLabel(parent, "name");
		txFirstName = createText(parent);
		
		createLabel(parent, "lastname");
		txLastName = createText(parent);
		
		createLabel(parent, "age");
		txAge = createText(parent);
	}
	
	@Override
	public void setInput(Person input) {
		
		txFirstName.setText(input.getName());
		txLastName.setText(input.getLastName());
		txAge.setText(Integer.toString(input.getAge()));
		
		super.setInput(input);
	}
}
